/*
package com.wy.sevice;


import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.*;

@WebServlet("")

public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String username = request.getParameter("username");
        String password = request.getParameter("password");

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/top_news?&useSSL=false&serverTimezone=UTC", "root", "123456");
            PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM news_user WHERE username=? AND user_pwd=?");
            pstmt.setString(1, username);
            pstmt.setString(2, password);

            ResultSet rs = pstmt.executeQuery();

            if (rs.next()) {
                response.sendRedirect("/login/loginerror.jsp");
            } else {
                response.sendRedirect("login/login.jsp?error=1");
            }
            rs.close();
            pstmt.close();
            conn.close();
        } catch (ClassNotFoundException | SQLException e) {
            throw new ServletException("Database error", e);
        }
    }
}
666666666
*/

